package net.zjitc.config;

import javax.servlet.Filter;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class ServletContainerInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    //初始化 Spring 容器 加载根配置类 加载数据源、事务管理器、SqlSessionFactory
    @Override
    protected Class<?>[]getRootConfigClasses(){
        return new Class[]{MyBatisConfig.class};
    }
    //初始化 SpringMVC 容器 加载springmvc配置类 加载控制器、视图解析器等
    @Override
    protected Class<?>[]getServletConfigClasses(){
        return new Class[]{SpringMvcConfig.class};
    }
    //设置 DispatcherServlet 的映射路径 拦截所有请求
    @Override
    protected String[]getServletMappings(){
        return new String[]{"/"};
    }



    // 配置过滤器
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter();
        encodingFilter.setEncoding("UTF-8");
        encodingFilter.setForceEncoding(true);
        return new Filter[]{encodingFilter};
    }
}
